Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
Imports DataAccesGenerales
Imports DataAcces

Public Class DataAccesInventario_Naviero_Detalle
  Private Const consTimeOut As Integer = 0 
  
  ''' <summary>
  ''' Funcion para Insertar un regristro en la tabla Inventario_Naviero_Detalle
  ''' </summary>
  Public Function Inventario_Naviero_Detalle_Insertar(pnidInventarioNaviero As Integer, pnidDocumento As Integer, ppuerto As String, pconocimiento As String, pmarcasNumero As String, pcantidad As Integer, ppeso As Integer, ppedimento As Integer, palmacen As String, parea As String, pdesc_Mcia As String, pnumero_Mov As String, pvid As Integer, paveria As String, pcant_Averia As Integer, ppeso_Averia As Integer, pvoluminoso As Char, pf_Arribo As String, pmaniobrista As String, pclase As String, pnum_Contenedor As String, psello As String, pcapacidad As String, pestado As String) As Byte
    Dim pTransaccion As Byte = 0
    Dim mensaje As String = String.Empty
    Try
      Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
        Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
          oraCommandDocumentos.Connection = oraConnection
          oraCommandDocumentos.CommandTimeout = consTimeOut
          oraCommandDocumentos.CommandType = CommandType.StoredProcedure
          oraCommandDocumentos.CommandText = "EDIV2.MI_EDIV2GENERALES.Inventario_Naviero_DetalleInsertar" 
          oraCommandDocumentos.Parameters.Add("pnidInventarioNaviero", pnidInventarioNaviero)
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("ppuerto", ppuerto)
          oraCommandDocumentos.Parameters.Add("pconocimiento", pconocimiento)
          oraCommandDocumentos.Parameters.Add("pmarcasNumero", pmarcasNumero)
          oraCommandDocumentos.Parameters.Add("pcantidad", pcantidad)
          oraCommandDocumentos.Parameters.Add("ppeso", ppeso)
          oraCommandDocumentos.Parameters.Add("ppedimento", ppedimento)
          oraCommandDocumentos.Parameters.Add("palmacen", palmacen)
          oraCommandDocumentos.Parameters.Add("parea", parea)
          oraCommandDocumentos.Parameters.Add("pdesc_Mcia", pdesc_Mcia)
          oraCommandDocumentos.Parameters.Add("pnumero_Mov", pnumero_Mov)
          oraCommandDocumentos.Parameters.Add("pvid", pvid)
          oraCommandDocumentos.Parameters.Add("paveria", paveria)
          oraCommandDocumentos.Parameters.Add("pcant_Averia", pcant_Averia)
          oraCommandDocumentos.Parameters.Add("ppeso_Averia", ppeso_Averia)
          oraCommandDocumentos.Parameters.Add("pvoluminoso", pvoluminoso)
          oraCommandDocumentos.Parameters.Add("pf_Arribo", pf_Arribo)
          oraCommandDocumentos.Parameters.Add("pmaniobrista", pmaniobrista)
          oraCommandDocumentos.Parameters.Add("pclase", pclase)
          oraCommandDocumentos.Parameters.Add("pnum_Contenedor", pnum_Contenedor)
          oraCommandDocumentos.Parameters.Add("psello", psello)
          oraCommandDocumentos.Parameters.Add("pcapacidad", pcapacidad)
          oraCommandDocumentos.Parameters.Add("pestado", pestado)

          oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

          oraConnection.Open()
          oraCommandDocumentos.ExecuteNonQuery()
          pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
          mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
          oraConnection.Close()
        End Using
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return pTransaccion
  End Function

  ''' <summary>
  ''' Funcion para Modificar un regristro en la tabla Inventario_Naviero_Detalle
  ''' </summary>
  Public Function Inventario_Naviero_Detalle_Modificar(pnidInventarioNaviero As Integer, pnidDocumento As Integer, ppuerto As String, pconocimiento As String, pmarcasNumero As String, pcantidad As Integer, ppeso As Integer, ppedimento As Integer, palmacen As String, parea As String, pdesc_Mcia As String, pnumero_Mov As String, pvid As Integer, paveria As String, pcant_Averia As Integer, ppeso_Averia As Integer, pvoluminoso As Char, pf_Arribo As String, pmaniobrista As String, pclase As String, pnum_Contenedor As String, psello As String, pcapacidad As String, pestado As String) As Byte
    Dim pTransaccion As Byte = 0
    Dim mensaje As String = String.Empty
    Try
      Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
        Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
          oraCommandDocumentos.Connection = oraConnection
          oraCommandDocumentos.CommandTimeout = consTimeOut
          oraCommandDocumentos.CommandType = CommandType.StoredProcedure
          oraCommandDocumentos.CommandText = "EDIV2.MI_EDIV2GENERALES.Inventario_Naviero_DetalleModificar"
          oraCommandDocumentos.Parameters.Add("pnidInventarioNaviero", pnidInventarioNaviero)
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("ppuerto", ppuerto)
          oraCommandDocumentos.Parameters.Add("pconocimiento", pconocimiento)
          oraCommandDocumentos.Parameters.Add("pmarcasNumero", pmarcasNumero)
          oraCommandDocumentos.Parameters.Add("pcantidad", pcantidad)
          oraCommandDocumentos.Parameters.Add("ppeso", ppeso)
          oraCommandDocumentos.Parameters.Add("ppedimento", ppedimento)
          oraCommandDocumentos.Parameters.Add("palmacen", palmacen)
          oraCommandDocumentos.Parameters.Add("parea", parea)
          oraCommandDocumentos.Parameters.Add("pdesc_Mcia", pdesc_Mcia)
          oraCommandDocumentos.Parameters.Add("pnumero_Mov", pnumero_Mov)
          oraCommandDocumentos.Parameters.Add("pvid", pvid)
          oraCommandDocumentos.Parameters.Add("paveria", paveria)
          oraCommandDocumentos.Parameters.Add("pcant_Averia", pcant_Averia)
          oraCommandDocumentos.Parameters.Add("ppeso_Averia", ppeso_Averia)
          oraCommandDocumentos.Parameters.Add("pvoluminoso", pvoluminoso)
          oraCommandDocumentos.Parameters.Add("pf_Arribo", pf_Arribo)
          oraCommandDocumentos.Parameters.Add("pmaniobrista", pmaniobrista)
          oraCommandDocumentos.Parameters.Add("pclase", pclase)
          oraCommandDocumentos.Parameters.Add("pnum_Contenedor", pnum_Contenedor)
          oraCommandDocumentos.Parameters.Add("psello", psello)
          oraCommandDocumentos.Parameters.Add("pcapacidad", pcapacidad)
          oraCommandDocumentos.Parameters.Add("pestado", pestado)

          oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

          oraConnection.Open()
          oraCommandDocumentos.ExecuteNonQuery()
          pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
          mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
          oraConnection.Close()
        End Using
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return pTransaccion
  End Function
  
  ''' <summary>
  ''' Funcion para consultar un registro de la tabla Inventario_Naviero_Detalle
  ''' </summary>
  ''' <param name="nidDocumento">numero de documento</param>
  ''' <returns>DataTable</returns>
  ''' <remarks></remarks>
  Public Function Inventario_Naviero_Detalle_Consultar(pNidDocumento as Integer) As DataTable
    Dim dtResultado As New DataTable("Inventario_Naviero_DetalleConsulta")
    Try
      Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
        Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
          oraCommandDocumentos.Connection = oraConnection
          oraCommandDocumentos.CommandTimeout = consTimeOut
          oraCommandDocumentos.CommandType = CommandType.StoredProcedure
          oraCommandDocumentos.CommandText = "EDIV2.MI_EDIV2GENERALES.Inventario_Naviero_DetalleConsultar" 
          oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
          oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

          Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
          oraDataAdapter.Fill(dtResultado)
          oraConnection.Close()
        End Using
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return dtResultado
  End Function
  
  ''' <summary>
  ''' Funcion para generar un combo de la tabla Inventario_Naviero_Detalle
  ''' </summary>
  ''' <param name="pNombre">nombre a buscar en la tabla</param>
  ''' <returns>DataTable</returns>
  ''' <remarks>si el nombre es "" retornara todos los registros</remarks>
  Public Function Inventario_Naviero_Detalle_Combo(pNombre As String) As DataTable
    Dim dtResultado As New DataTable("Inventario_Naviero_DetalleCombo")
    Try
      Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
        Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
          oraCommandDocumentos.Connection = oraConnection
          oraCommandDocumentos.CommandTimeout = consTimeOut
          oraCommandDocumentos.CommandType = CommandType.StoredProcedure
          oraCommandDocumentos.CommandText = "EDIV2.MI_EDIV2GENERALES.Inventario_Naviero_DetalleCombo" 
		  oraCommandDocumentos.Parameters.Add("pNombre", pNombre)
          oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

          Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
          oraDataAdapter.Fill(dtResultado)
          oraConnection.Close()
        End Using
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return dtResultado
  End Function
  
  ''' <summary>
  ''' Funcion para generar la cadena XML Chilkat del documento de la tabla Inventario_Naviero_Detalle
  ''' </summary>
  ''' <param name="nidDocumento"> numero del documento</param>
  ''' <returns>Chilkat.Xml</returns>
  ''' <remarks></remarks>
  Public Function Inventario_Naviero_Detalle_CadenaOriginalXMLChilkat(nidDocumento As Integer) As Chilkat.Xml
    Dim detalleDataSet As New DataSet("DatosInventario_Naviero_Detalle")
    Try
      detalleDataSet = Inventario_Naviero_Detalle_DetalleXML(nidDocumento)
	  'En esta parte van las tablas obtenidas en la consulta anterior
	  'separadas dependiendo del reporte a crear, ejemplo:
	  detalleDataSet.Tables(0).TableName = "Informacion del Tramite"
      detalleDataSet.Tables(1).TableName = "Datos Inventario_Naviero_Detalle"
      detalleDataSet.Tables(2).TableName = "Archivos Anexos"
      detalleDataSet.Tables(3).TableName = "Incidencias"

      Dim xml As New Chilkat.Xml
      xml.LoadXml(detalleDataSet.GetXml())
      Return xml 'detalleDataSet.GetXml()
    Catch ex As Exception
      Throw ex
    End Try
  End Function

  ''' <summary>
  ''' Funcion para consultar el detalle del documento de la tabla Inventario_Naviero_Detalle
  ''' </summary>
  ''' <param name="nidDocumento">numero del documento</param>
  ''' <returns>DataSet</returns>
  ''' <remarks></remarks>
  Public Function Inventario_Naviero_Detalle_DetalleXML(ByVal nidDocumento As Integer) As DataSet
    Dim dsDetalle As New DataSet("Inventario_Naviero_DetalleDetalle")
    Dim pTransaccion As Byte = 0
    Try
      Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
        Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
          oraCommandDocumentos.Connection = oraConnection
          oraCommandDocumentos.CommandTimeout = consTimeOut
          oraCommandDocumentos.CommandType = CommandType.StoredProcedure
          oraCommandDocumentos.CommandText = "EDIV2.MI_EDIV2GENERALES.Inventario_Naviero_DetalleDetalleXML"
          oraCommandDocumentos.Parameters.Add("pNidDocumento", nidDocumento)
          oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
          'En esta parte es para los cursores necesario 
		  oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pEncabezado", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pDatos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pAnexos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pIncidencias", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
		
          Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
          'pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
          oraDataAdapter.Fill(dsDetalle)
        End Using
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return dsDetalle
  End Function
  
  ''' <summary>
  ''' Funcion para generar la integracion del documento de la tabla Inventario_Naviero_Detalle
  ''' </summary>
  ''' <param name="pNidDocumento">numero del documento</param>
  ''' <returns>Byte</returns>
  ''' <remarks></remarks>
  Public Function Inventario_Naviero_Detalle_Integracion(pNidDocumento As Integer) As Byte
    Dim pTransaccion As Byte = 0
    Dim mensaje As String = String.Empty
    Try
      Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
        Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
          oraCommandDocumentos.Connection = oraConnection
          oraCommandDocumentos.CommandTimeout = consTimeOut
          oraCommandDocumentos.CommandType = CommandType.StoredProcedure
          oraCommandDocumentos.CommandText = "EDIV2.MI_EDIV2GENERALES.Inventario_Naviero_DetalleIntegracion"
          oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
          oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
          oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

          oraConnection.Open()
          oraCommandDocumentos.ExecuteNonQuery()
          pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
          mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
          oraConnection.Close()
        End Using
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return pTransaccion
  End Function
  
  Public Function Inventario_Naviero_Detalle_Borrar(pnid As Integer) As Byte
    Dim pTransaccion As Byte = 0
    Dim mensaje As String = String.Empty
    Try
      Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
        Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
          oraCommandDocumentos.Connection = oraConnection
          oraCommandDocumentos.CommandTimeout = consTimeOut
          oraCommandDocumentos.CommandType = CommandType.StoredProcedure
          oraCommandDocumentos.CommandText = "EDIV2.MI_EDIV2GENERALES.Inventario_Naviero_DetalleBorrar"
          oraCommandDocumentos.Parameters.Add("pnid", pnid)
          oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
          
          oraConnection.Open()
          oraCommandDocumentos.ExecuteNonQuery()
          pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
          oraConnection.Close()
        End Using
      End Using
    Catch ex As Exception
      Throw ex
    End Try
    Return pTransaccion
  End Function
  
End Class
